/* Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * openUBMC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#ifndef __L_RESPONDER_COLLECTION_H__
#define __L_RESPONDER_COLLECTION_H__

#include "luawrapper.h"
#include "spdm_command_impl.h"
#include "responder.h"
#include "common.h"

class ResponderCollection {
private:
    vector<Responder> responderCollection;

    Responder *GetResponderByName(const string& deviceName);

public:
    ResponderCollection() {};
    ~ResponderCollection();
    void Init();
    void Free();
    int32_t GetResponderCount();
    void NewResponder(const string& deviceName, const string& componentType, const string& inventoryPath);
    
    int32_t NewSpdmCtx(const string& deviceName);
    int32_t InitSpdmCtx(const string& deviceName, uint8_t type);
    int32_t CheckSpdmCtx(const string& deviceName);
    void FreeSpdmCtx(const string& deviceName);

    int32_t InitSpdmConnection(const string& deviceName);
    tuple<int32_t, uint8_t> GetDigests(const string& deviceName);
    luawrap::stack_value GetCertificate(lua_State *L, const string& deviceName, uint8_t slot_id);
    int32_t ChallengeAuth(const string& deviceName, uint8_t slot_id);
    luawrap::stack_value GetIntegrity(lua_State *L, const string& deviceName);
    int32_t InitMeasurements(const string& deviceName, uint8_t slot_id);
    luawrap::stack_value GetMeasurementSet(lua_State *L, const string& deviceName);
    luawrap::stack_value GetOneMeasurement(lua_State *L, const string& deviceName, uint8_t index);
    luawrap::stack_value GetSignedMeasurement(lua_State *L, const string& deviceName, vector<uint8_t> indices,
        uint8_t slot_id, const string& nonce);

#ifdef G_ENABLE_TEST
    int32_t TrySendMsgToCb(const string& deviceName, const string& data);
    luawrap::n_ret TryGetMsg(lua_State *L, const string& deviceName);
#endif // G_ENABLE_TEST

    static void  register_to(lua_State *L, luawrap::stack_table &t);
};

#endif // __L_RESPONDER_COLLECTION_H__